﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

namespace Jerkymon.Web
{
    /// Abstract base class for a skinned control.
    public abstract class SkinnedControlBase :
                          Control, INamingContainer
    {
        private string skinPath = null;

        /// Virtual path to the skin file.
        public string SkinPath
        {
            get { return skinPath; }
            set { skinPath = value; }
        }

        protected override void CreateChildControls()
        {
            //Clear the control tree and (re)build it
            Controls.Clear();
            base.CreateChildControls();

            //Load the skin (should check existence first)
            Control skin = Page.LoadControl(skinPath);

            //Add the skin to the controls collection
            Controls.Add(skin);

            //Initalize the control
            Initialize(skin);
        }

        /// Initializes the skinned control. In this method, the
        /// controls in the skin need to be attached to the
        /// controls in the skinned control.
        /// <param name="skin">The skin to apply</param>
        protected abstract void Initialize(Control skin);
    }
}
